#include <bits/stdc++.h>
using namespace std;

struct ElemType{
    int x, y;
};
struct StackNode{
    ElemType data;
    StackNode *next;
};
using LinkStack = StackNode*;

void InitStack(LinkStack &S){
    S = NULL;
}

void Push(LinkStack &S, ElemType e){
    StackNode *p = new StackNode;
    p->data = e;
    p->next = S;
    S = p;
}

void Pop(LinkStack &S, ElemType &e){
    if(!S) return;
    StackNode *p = S;
    e = p->data;
    S = S->next;
    delete p;
}

void GetTop(const LinkStack &S, ElemType &e){
    if(!S) return;
    e = S->data;
}

void Show(const LinkStack &S){
    if(!S) return;
    StackNode *p = S;
    while(p){
        cout << p->data.x << " " << p->data.y << '\n';
        p = p->next;
    }
}
int main(){
    LinkStack S; // S是栈顶指针
    InitStack(S);

    int n; cin >> n;
    while(n--){
        ElemType e;
        cin >> e.x >> e.y;
        Push(S, e);
    }
    Show(S);
    cout << '\n';

    ElemType top;
    GetTop(S, top);
    cout << top.x << " " << top.y << '\n';
    cout << '\n';

    ElemType popTop;
    Pop(S, popTop);
    cout << popTop.x << " " << popTop.y << '\n';
    cout << '\n';

    Show(S);
    return 0;
}